from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-07-02 14:02:18.912992
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 02, Jul, 2022
Time: 14:02:23
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.6679
Nobs: 705.000 HQIC: -50.0249
Log likelihood: 8799.87 FPE: 1.50251e-22
AIC: -50.2498 Det(Omega_mle): 1.32363e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.298561 0.057573 5.186 0.000
L1.Burgenland 0.106903 0.037836 2.825 0.005
L1.Kärnten -0.109487 0.020034 -5.465 0.000
L1.Niederösterreich 0.210622 0.079025 2.665 0.008
L1.Oberösterreich 0.106586 0.077417 1.377 0.169
L1.Salzburg 0.256761 0.040453 6.347 0.000
L1.Steiermark 0.045056 0.052707 0.855 0.393
L1.Tirol 0.109301 0.042785 2.555 0.011
L1.Vorarlberg -0.058679 0.037117 -1.581 0.114
L1.Wien 0.039819 0.068470 0.582 0.561
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.048594 0.120694 0.403 0.687
L1.Burgenland -0.033853 0.079319 -0.427 0.670
L1.Kärnten 0.041087 0.041999 0.978 0.328
L1.Niederösterreich -0.167996 0.165666 -1.014 0.311
L1.Oberösterreich 0.424463 0.162295 2.615 0.009
L1.Salzburg 0.288438 0.084804 3.401 0.001
L1.Steiermark 0.100672 0.110492 0.911 0.362
L1.Tirol 0.319236 0.089692 3.559 0.000
L1.Vorarlberg 0.027894 0.077811 0.358 0.720
L1.Wien -0.041093 0.143538 -0.286 0.775
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.187393 0.029479 6.357 0.000
L1.Burgenland 0.090070 0.019373 4.649 0.000
L1.Kärnten -0.008003 0.010258 -0.780 0.435
L1.Niederösterreich 0.264919 0.040463 6.547 0.000
L1.Oberösterreich 0.138384 0.039639 3.491 0.000
L1.Salzburg 0.045932 0.020713 2.218 0.027
L1.Steiermark 0.019764 0.026987 0.732 0.464
L1.Tirol 0.091494 0.021907 4.177 0.000
L1.Vorarlberg 0.056952 0.019005 2.997 0.003
L1.Wien 0.114375 0.035058 3.262 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111640 0.029988 3.723 0.000
L1.Burgenland 0.045388 0.019708 2.303 0.021
L1.Kärnten -0.013693 0.010435 -1.312 0.189
L1.Niederösterreich 0.192279 0.041161 4.671 0.000
L1.Oberösterreich 0.302342 0.040324 7.498 0.000
L1.Salzburg 0.108149 0.021070 5.133 0.000
L1.Steiermark 0.104834 0.027453 3.819 0.000
L1.Tirol 0.103696 0.022285 4.653 0.000
L1.Vorarlberg 0.067459 0.019333 3.489 0.000
L1.Wien -0.022778 0.035664 -0.639 0.523
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.134598 0.054706 2.460 0.014
L1.Burgenland -0.051436 0.035952 -1.431 0.153
L1.Kärnten -0.044404 0.019036 -2.333 0.020
L1.Niederösterreich 0.157007 0.075090 2.091 0.037
L1.Oberösterreich 0.139582 0.073562 1.897 0.058
L1.Salzburg 0.286656 0.038438 7.458 0.000
L1.Steiermark 0.047645 0.050081 0.951 0.341
L1.Tirol 0.167003 0.040654 4.108 0.000
L1.Vorarlberg 0.093033 0.035269 2.638 0.008
L1.Wien 0.072621 0.065060 1.116 0.264
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.055204 0.043498 1.269 0.204
L1.Burgenland 0.037691 0.028587 1.319 0.187
L1.Kärnten 0.051096 0.015136 3.376 0.001
L1.Niederösterreich 0.217155 0.059706 3.637 0.000
L1.Oberösterreich 0.295046 0.058491 5.044 0.000
L1.Salzburg 0.047882 0.030564 1.567 0.117
L1.Steiermark 0.001825 0.039821 0.046 0.963
L1.Tirol 0.140590 0.032325 4.349 0.000
L1.Vorarlberg 0.073898 0.028043 2.635 0.008
L1.Wien 0.080501 0.051731 1.556 0.120
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.175383 0.052027 3.371 0.001
L1.Burgenland -0.002319 0.034191 -0.068 0.946
L1.Kärnten -0.063037 0.018104 -3.482 0.000
L1.Niederösterreich -0.081126 0.071412 -1.136 0.256
L1.Oberösterreich 0.194906 0.069959 2.786 0.005
L1.Salzburg 0.056381 0.036556 1.542 0.123
L1.Steiermark 0.236146 0.047629 4.958 0.000
L1.Tirol 0.497625 0.038663 12.871 0.000
L1.Vorarlberg 0.045008 0.033541 1.342 0.180
L1.Wien -0.056420 0.061874 -0.912 0.362
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.169955 0.059150 2.873 0.004
L1.Burgenland -0.012836 0.038873 -0.330 0.741
L1.Kärnten 0.063920 0.020583 3.106 0.002
L1.Niederösterreich 0.207030 0.081190 2.550 0.011
L1.Oberösterreich -0.077610 0.079537 -0.976 0.329
L1.Salzburg 0.213181 0.041561 5.129 0.000
L1.Steiermark 0.126362 0.054150 2.334 0.020
L1.Tirol 0.067075 0.043956 1.526 0.127
L1.Vorarlberg 0.119208 0.038134 3.126 0.002
L1.Wien 0.126132 0.070345 1.793 0.073
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.363161 0.034282 10.593 0.000
L1.Burgenland 0.007584 0.022530 0.337 0.736
L1.Kärnten -0.023754 0.011929 -1.991 0.046
L1.Niederösterreich 0.215777 0.047056 4.586 0.000
L1.Oberösterreich 0.205382 0.046099 4.455 0.000
L1.Salzburg 0.043376 0.024088 1.801 0.072
L1.Steiermark -0.014888 0.031384 -0.474 0.635
L1.Tirol 0.106010 0.025476 4.161 0.000
L1.Vorarlberg 0.069492 0.022102 3.144 0.002
L1.Wien 0.030210 0.040771 0.741 0.459
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037360 0.138275 0.193962 0.155100 0.114958 0.101865 0.058194 0.217899
Kärnten 0.037360 1.000000 -0.015481 0.134240 0.055897 0.095224 0.435657 -0.053118 0.093353
Niederösterreich 0.138275 -0.015481 1.000000 0.335167 0.141208 0.294346 0.092505 0.176683 0.312380
Oberösterreich 0.193962 0.134240 0.335167 1.000000 0.226473 0.324758 0.175971 0.164559 0.264085
Salzburg 0.155100 0.055897 0.141208 0.226473 1.000000 0.137876 0.116436 0.138894 0.130171
Steiermark 0.114958 0.095224 0.294346 0.324758 0.137876 1.000000 0.145580 0.129366 0.073333
Tirol 0.101865 0.435657 0.092505 0.175971 0.116436 0.145580 1.000000 0.112860 0.141956
Vorarlberg 0.058194 -0.053118 0.176683 0.164559 0.138894 0.129366 0.112860 1.000000 0.004596
Wien 0.217899 0.093353 0.312380 0.264085 0.130171 0.073333 0.141956 0.004596 1.000000